<!--
 * @Description: 原物料结算审批
 * @Author: wangwangwang
 * @Date: 2020-11-18 15:34:16
 * @LastEditors: wangwangwang
 * @LastEditTime: 2021-04-23 14:38:19
-->
<template>
  <div class="flows-content">
    <el-container>
      <el-main style="margin-bottom: 20px; padding: 0;">
        <el-container direction="vertical">
          <FlowHeader :isReadOnly="readOnly" @saveSubmit="handleSubmit(1)" @sendSubmit="handleSubmit(2)" @handleBackEnd="handleSubmit(3)" @handleCC="handleSubmit(4)" @handleAssign="handleSubmit(5)" @handleBackUp="handleSubmit(6)" @handleAssist="handleSubmit(7)" @handleNode="handleSubmit(8)" @handleNodeImage="handleSubmit(9)" @handleCollection="handleSubmit(10)" />
          <el-main class="info">
            <div>
              <el-input v-model="title" class="flow-title" :disabled="$route.query.type*1!==1" placeholder="请输入流程标题"></el-input>
            </div>
            <div class="info-top">
              <div class="left">
                <span>单据号码：{{billCode}}</span>
                <span class="text">制单日期：{{billDate}}</span>
              </div>
              <div class="right">
                <span>发起人：{{applyPerson}}</span>
                <span class="text">状态：{{taskTypeText[taskStatus*1]}}</span>
              </div>
            </div>
            <div>
              <div style="padding:10px 0">
                <span>公司：</span>
                <span style="padding-right:40px">{{billDetails1.company}}</span>
                <span>供应商：</span>
                <span>{{billDetails1.supplier}}</span>
              </div>
              <div class="bill_title1" style="padding-bottom: 15px;padding-top:0">结算信息</div>
              <el-table v-if="billDetails1.list" :header-cell-style="{ background: '#f3f6f9' }" :cell-style="{ borderRight: 'none'}" border stripe style="width: 100%" :data="billDetails1.list" tooltip-effect="dark">
                <el-table-column label="开票单位" align="center" prop="cooperativeUnit" width="120"></el-table-column>
                <el-table-column label="结算物料" align="center" prop="rawName" width="120"></el-table-column>
                <el-table-column label="时间段" align="center" width="360">
                  <template slot-scope="scope">
                    {{scope.row.startTime}}至{{scope.row.endTime}}
                  </template>
                </el-table-column>
                <el-table-column label="站点" align="center" prop="receiveStation" width="120"></el-table-column>
                <el-table-column label="单价（元）" align="center" prop="statementUnitPrice" width="120"></el-table-column>
                <el-table-column label="收货量" align="center" prop="receiveNum" width="120"></el-table-column>
                <el-table-column label="结算单价（元）" align="center" width="120" prop="statementUnitPrice">
                </el-table-column>
                <el-table-column label="结算量（吨）" align="center" width="120" prop="statementNum">
                </el-table-column>
                <el-table-column label="应付金额（元）" align="center" prop="dealPrice" width="120">
                </el-table-column>
                <el-table-column label="增加金额（元）" align="center" width="120" prop="increaseAmount">
                </el-table-column>
                <el-table-column label="结算金额（元）" align="center" width="120" prop="dealPrice">
                </el-table-column>
                <el-table-column label="增加金额备注" align="center" width="220" prop="remark">
                </el-table-column>
              </el-table>
              <div v-if="billDetails1.list" class="combined">小计：{{combined(billDetails1.list)}}</div>
              <!-- 结算补差 -->
              <div class="bill_title">结算补差</div>
              <el-table :header-cell-style="{ background: '#f3f6f9' }" :cell-style="{ borderRight: 'none' }" border stripe style="width: 100%" :data="billDetails1.compensateList" tooltip-effect="dark">
                <el-table-column label="开票单位" align="center" prop="cooperativeUnit"></el-table-column>
                <el-table-column label="物料名称" align="center" prop="rawName"></el-table-column>
                <el-table-column label="补差日期" align="center">
                  <template slot-scope="scope">
                    {{scope.row.compensateStartTime+'-'+scope.row.compensateEndTime}}
                  </template>
                </el-table-column>
                <el-table-column label="补差数量" align="center" prop="compensateNum">
                </el-table-column>
                <el-table-column label="补差单价（元）" align="center" prop="compensatePrice">
                </el-table-column>
                <el-table-column label="补差金额（元）" align="center" prop="compensateAmount">
                </el-table-column>
              </el-table>
              <!-- 扣减金额 -->
              <div class="bill_title">扣减金额</div>
              <el-table :header-cell-style="{ background: '#f3f6f9' }" :cell-style="{ borderRight: 'none' }" border stripe style="width: 100%" :data="billDetails1.deductionList" tooltip-effect="dark">
                <el-table-column label="协作单位" align="center" prop="cooperativeUnit"></el-table-column>
                <el-table-column label="站点" align="center" prop="station"></el-table-column>
                <el-table-column label="扣减类型" align="center" prop="deductionType"></el-table-column>
                <el-table-column label="扣减金额" align="center" prop="deduction"></el-table-column>
                <el-table-column label="是否影响开票" align="center">
                  <template slot-scope="scope">
                    <div v-if="scope.row.influenceInvoice==1">是</div>
                    <div v-if="scope.row.influenceInvoice==0">否</div>
                  </template>
                </el-table-column>
                <el-table-column label="备注" align="center" prop="remark"></el-table-column>
              </el-table>
              <!-- 结算合计 -->
              <div class="bill_title">结算合计</div>
              <el-table :header-cell-style="{ background: '#f3f6f9' }" :cell-style="{ borderRight: 'none' }" border stripe style="width: 100%" :data="billDetails1.totalList" tooltip-effect="dark">
                <el-table-column label="开票单位" align="center" prop="cooperativeUnit"></el-table-column>
                <el-table-column label="结算金额（元）" align="center">
                  <template slot-scope="scope">
                    <div>{{scope.row.settlementAmount||scope.row.settlementAmount==0?scope.row.settlementAmount:'---'}}</div>
                  </template>
                </el-table-column>
                <el-table-column label="补差金额（元）" align="center">
                  <template slot-scope="scope">
                    <div>{{scope.row.compensateAmount||scope.row.compensateAmount==0?scope.row.compensateAmount:'---'}}</div>
                  </template>
                </el-table-column>
                <el-table-column label="扣减金额（元）" align="center">
                  <template slot-scope="scope">
                    <div>{{scope.row.deduction||scope.row.deduction==0?scope.row.deduction:'---'}}</div>
                  </template>
                </el-table-column>
                <el-table-column label="实付金额（元）" align="center">
                  <template slot-scope="scope">
                    <div>{{scope.row.realPay||scope.row.realPay==0?scope.row.realPay:'---'}}</div>
                  </template>
                </el-table-column>
                <el-table-column label="票面调整（元）" align="center" prop="faceAdjustment">
                </el-table-column>
              </el-table>
            </div>
            <div class="flows-details">
              <FlowContent ref="flowcontent" :title='title' :showSendVisible="showSendVisible" @handleCancel="handleCancel" @sendCode="sendCode" @handleFinish="handleFinish" @handleBusiness="handleBusiness" />
            </div>
          </el-main>
        </el-container>
      </el-main>
    </el-container>
  </div>
</template>
<script>
import FlowContent from '@/components/WorkFlow/flowContent';
import FlowHeader from '@/components/WorkFlow/flowHeader';
import { getUserInfo } from "@/utils/auth.js";
import {
  get_statement_detail,
  update_audit_status,
} from "@/api/wise/material.js";
import addTab from "@/common/addTab.js";
export default {
  components: {
    FlowContent,
    FlowHeader,
  },
  data() {
    return {
      type: 0,
      title: '原物料结算审批',
      billCode: '',
      billDate: '',
      applyPerson: '',
      taskTypeText: ['发起', '已保存', '审批中', '已完成', '撤销', '不通过'],
      taskStatus: 0,
      readOnly: false,
      showSendVisible: false,
      billDetails1: { list: [] },
    }
  },
  methods: {
    /**结算信息合计*/
    combined(arr) {
      let num = 0
      arr.forEach(res => {
        num = Number(res.dealPrice) - Number(res.deductAmount) + Number(res.increaseAmount) + num
      })
      return num.toFixed(2)
    },
    handleBusiness() {
      const { query } = this.$route;
      const params = {
        process_success: {
          url: '/icps/system/sign/settlement/raw/rawStatement/update_audit_status',
          data: {
            statementNo: JSON.parse(query.dataContent).id,
            auditStatus: 3
          },
          httpMethod: 'post',
        },
        process_failure: {
          url: '/icps/system/sign/settlement/raw/rawStatement/update_audit_status',
          data: {
            statementNo: JSON.parse(query.dataContent).id,
            auditStatus: 4
          },
          httpMethod: 'post',
        }
      }
      this.showSendVisible = false;
      this.$refs.flowcontent.handleToFlow(params);
    },
    /**
     * @Description: 
     * @Param: 1为保存，2为最后提交
     * @Author: wangwangwang
     * @param {*} type
     */
    handleFinish(type) {
      const { query } = this.$route;
      if (type == 1) {
        update_audit_status({
          statementNo: query.id,
          auditStatus: 2,
        }).then((res) => {
          if (res.code == 1001) {
            addTab.$emit("remove", this.$route.name);
          }
        })
        return
      }
    },
    handleSubmit(type) {
      const { query } = this.$route;
      if (query.type * 1 === 2 && type === 2 && query.taskType * 1 !== 2) { // 发起流程
        this.showSendVisible = true;
        return
      }
      const data = {
        dataSource: 'sign_material',
        dataContent: JSON.stringify({ id: query.id }), // 业务数据
      }
      this.$refs.flowcontent.saveFlows(type, data);
    },
    handleFlowChat() {
      this.$refs.flowcontent.showFlowNode()
    },
    handleCancel() {
      this.showSendVisible = false;
    },
    /**
     * @Description: 回显业务数据
     * @Param: 
     * @Author: wangwangwang
     */
    initFlowsData(id) {
      get_statement_detail({ statementNo: id }).then(res => {
        this.billDetails1 = res.data
      })
      const { query } = this.$route;
      if (query.type * 1 !== 1) {
        this.title = query.taskName;
      }
      this.billCode = query.receiptNumber;
      this.billDate = query.createTime;
    },
    sendCode(code) {
      this.billCode = code;
    },
  },
  mounted() {
    const { query } = this.$route;
    if (query.type * 1 === 1) { // 发起流程
      this.initFlowsData(query.id);
      this.$refs.flowcontent.initBaseData('sign_material');
      this.billDate = new Date().Format('yyyy-MM-dd hh:mm:ss');
      this.applyPerson = getUserInfo().userRealName;
      return
    }
    this.initFlowsData(JSON.parse(query.dataContent).id);
    this.applyPerson = query.createUserName;
    this.taskStatus = query.taskStatus;
    if (query.isReadOnly*1===1) {
      this.readOnly = true;
    }
  }
}
</script>
<style lang="scss" scoped>
.bill_title {
  font-size: 18px;
  font-weight: 600;
  padding: 15px 0;
}
.bill_title1 {
  font-size: 18px;
  font-weight: 600;
  padding: 20px 0;
}
.bill_subtitle {
  padding: 20px 0;
  > span {
    padding-right: 20px;
  }
  .text {
    color: #000;
  }
}
.combined {
  border: 1px solid #ebeef5;
  text-align: center;
  line-height: 40px;
}
.flows-details {
  margin-top: 20px;
}
.info {
  padding: 0 20px;
  background: #fff;
  .info-top {
    font-size: $font_size;
    color: #000000;
    @include discen_al;
    justify-content: space-between;
    height: 50px;
    border-bottom: 1px #e1e5ed solid;
    .left {
      @include discen_al;
    }
    .text {
      margin-left: 60px;
    }
  }
}
.nav_title {
  @include discen_al;
  align-items: flex-end;
  > div {
    width: 4px;
    height: 24px;
    background: $bg_color;
    margin-right: 10px;
  }
  i {
    margin-left: 5px;
  }
  color: $bg_color;
  font-size: 20px;
  font-weight: bold;
}
.dialoginfo {
  padding: 0;
}
.active {
  border-top: 1px #e1e5ed solid;
  border-right: 1px #e1e5ed solid;
  border-left: 1px #e1e5ed solid;
  background: #fff;
}
.dialoginfo-info {
  border-right: 1px #e1e5ed solid;
  border-left: 1px #e1e5ed solid;
  border-bottom: 1px #e1e5ed solid;
}
/*弹窗*/
.dialoginfo-title {
  > div {
    cursor: pointer;
  }
  height: 48px;
  display: flex;
  background: linear-gradient(
    180deg,
    rgba(250, 252, 255, 1) 0%,
    rgba(245, 247, 250, 1) 100%
  );
  .none {
    font-weight: bold;
    height: 48px;
    @include discen;
    width: calc(calc(100% - 1px) / 2);
    border-bottom: 1px solid #e1e5ed;
    > div {
      line-height: 48px;
      border-bottom: 1px rgba(0, 0, 0, 0) solid;
    }
  }
  .center {
    width: 1px;
    height: 48px;
    background: #e1e5ed;
  }
  .active {
    font-weight: bold;
    height: 48px;
    @include discen;
    width: calc(calc(100% - 1px) / 2);
    border-bottom: 1px solid rgba(0, 0, 0, 0);
    > div {
      color: $bg_color;
      line-height: 48px;
      border-bottom: 1px $bg_color solid;
    }
  }
}
.dialoginfo-info {
  padding: 10px 20px;
  overflow: auto;
  height: calc(85vh - 282px);
  .el-select,
  .el-input,
  .el-date-picker {
    width: 100%;
  }
}
.form-title {
  font-size: 18px;
  margin: 10px 0;
  display: flex;
  justify-content: space-between;
}
</style>